package com.example.wangliang.piechartview;

import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private PieChartView pieChat1,pieChat2,pieChat3,pieChat4,pieChat5;
    private List<Map<String, Object>> list;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pieChat1 = (PieChartView) findViewById(R.id.pieChat1);
        pieChat2 = (PieChartView) findViewById(R.id.pieChat2);
        pieChat3 = (PieChartView) findViewById(R.id.pieChat3);
        pieChat4 = (PieChartView) findViewById(R.id.pieChat4);
        pieChat5 = (PieChartView) findViewById(R.id.pieChat5);

        initListener();

       list = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        map.put(PieChartView.KEY_NAME,"red");
        map.put(PieChartView.KEY_PERCENT,40);
        map.put(PieChartView.KEY_COLOR, Color.RED);
        list.add(map);
        map = new HashMap<>();
        map.put(PieChartView.KEY_NAME,"gray");
        map.put(PieChartView.KEY_PERCENT,30);
        map.put(PieChartView.KEY_COLOR, Color.GRAY);
        list.add(map);
        map = new HashMap<>();
        map.put(PieChartView.KEY_NAME,"blue");
        map.put(PieChartView.KEY_PERCENT,10);
        map.put(PieChartView.KEY_COLOR, Color.BLUE);
        list.add(map);
        map = new HashMap<>();
        map.put(PieChartView.KEY_NAME,"black");
        map.put(PieChartView.KEY_PERCENT,20);
        map.put(PieChartView.KEY_COLOR, Color.BLACK);
        list.add(map);

        pieChat1.performClick();
        pieChat2.performClick();
        pieChat3.performClick();
        pieChat4.performClick();
        pieChat5.performClick();




    }

    private void initListener() {
        pieChat1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pieChat1.setShowList(list,false);
                pieChat1.setShowText("无动画",Color.GREEN,90,PieChartView.TEXT_ALIGN_CENTER);
            }
        });
        pieChat2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pieChat2.setShowList(list,false);
                pieChat2.setStrokeWidth(0.6f);
                pieChat2.setShowText("无动画无动画",Color.GREEN,90,PieChartView.TEXT_ALIGN_CENTER_LEFT_TOP );

            }
        });
        pieChat3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pieChat3.setShowList(list,true);
                pieChat3.setShowText("无动画有动画",Color.GREEN,90,PieChartView.TEXT_ALIGN_CENTER_LEFT_BOTTOM);

            }
        });
        pieChat4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pieChat4.setShowList(list,true);
                pieChat4.setStrokeWidth(0.6f);
                pieChat4.setShowText("无动画有动画",Color.GREEN,90,PieChartView.TEXT_ALIGN_CENTER_RIGHT_TOP);

            }
        });
        pieChat5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pieChat5.setBackgroundImage(BitmapFactory.decodeResource(getResources(),R.drawable.girl));
                pieChat5.setShowText("饼状图设置背景",Color.GREEN,90,PieChartView.TEXT_ALIGN_CENTER_RIGHT_BOTTOM);

            }
        });
    }
}
